<!DOCTYPE html>
<html>
<head lang="en">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
    <link rel="shortcut icon" href="img/smlogo.png" type="image/x-icon">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="css/index2.css"/>
    <style>
        .user{
            height:100px;
            max-width:1000px;
            margin:64px auto 0;
            background: #fff;
            padding:14px;
            box-sizing: border-box;
            overflow: hidden;
        }
        .userimg{
            width:73px;
            height:73px;
            margin-right:26px;
        }
        .userimg>img{
            height: 72px;
            width: 72px;
        }
        .sex1,.sex2{
            display:none;
            width:13px;
            height:13px;
        }
        p.nick{
            overflow:hidden;
            font-size: 18px;
            color:#000;
        }
        p .nickword{padding-right:10px}
        p.loca{
            font-size:13px;
            color:#6a6a6a;
            margin-top:5px;
        }
        #addfribtn{
            height:55px;
            max-width:380px;
            width:85%;
            margin:0 auto;
            border:1px solid #1F9719;
            border-radius:5px;
            background:#1AAC19;
            color:#FFF;
            line-height: 55px;
            text-align: center;
            font-size:18px;
            margin-top:20px;
        }
        #addfribtn.not{
            border:1px solid #cdcdcd;
            background:#cdcdcd;
        }
        /*加好友完成提醒*/
        #sendfriendinfook{
            z-index:1000;
            width:100%;
            max-width:1000px;
            position:fixed;
            top:50%;
            transform: translateY(-50%);
            -moz-transform:translateY(-50%) ;
            -ms-transform:translateY(-50%) ;
            -o-transform:translateY(-50%) ;
            -webkit-transform:translateY(-50%) ;
        }
        #sendfriendinfook div{
            width:60%;
            max-width:220px;
            margin:0 auto;
            min-height:80px;
            /*line-height: 80px;*/
            text-align: center;
            font-size: 18px;
            color: #fff;
            background: rgba(53,53,53,0.5);
            overflow: hidden;
            border-radius: 4px;
            padding-top: 26px;
        }
        .errer{
            text-align: center;
            margin-top:15px;
            font-size: 13px;
            color:#b92b27;;
            height:18px;
        }
        .header_main{
            line-height:44px;
            color: rgba(255,255,255,0.85);
            font-size:16px;
        }

        #delmynews {
            display:none;
            background: rgba(0,0,0,0.75);
            z-index: 1001;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            width: 100%;
            height: 100vh;
            -webkit-user-select: none;
            -webkit-animation: modalIn 200ms ease-out 0s 1 normal;
            -o-animation: modalIn 200ms ease-out 0s 1 normal;
            animation: modalIn 200ms ease-out 0s 1 normal;
            -webkit-animation-fill-mode: both;
            -o-animation-fill-mode: both;
            animation-fill-mode: both;
        }
        #delmynews a::after{display:none;}
        #delmynews .inner {
            position: relative;
            width: 100%;
            height: 100%;
            max-width: 300px;
            box-sizing: border-box;
            margin: 0 auto;
        }
        #delmynews .inner>div {
            position: absolute;
            width: 100%;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            padding: 28px;
            padding-right: 20px;
            border-radius: 2px;
            background: #fff;
            box-sizing: border-box;
        }
        #delmynews .action_menu p{
            color:#808393;
            padding-top:5px;
        }
        #delmynewsform>div:first-child {
            padding-bottom: 20px;
        }
        #delmynews .inner .action_menu .mweb_action_button {
            padding: 0;
            color: #000;
            text-align: left;
            font-size: 20px;
        }
        #delmynewsform>div:last-child {
            margin-top: 20px;
            text-align: right;
        }
        #delmynewsok, #delmynewscancel {
            font-size: 18px;
            width: 90px;
            padding: 0;
            color: #7B7B7B;
            border: none;
            cursor: pointer;
            box-sizing: border-box;
            text-align: center;
            display: inline-block;
        }
        #delmynewsok {
            color: #1BAD1A;
        }
    </style>
</head>
<body>
<div class="Header">
    <div class="fixed_header">
        <div class="header_main">
            <a class="logo symbol_logo" id="logo"></a>
            <span>关注</span>
        </div>
    </div>
</div>
<div class="user">
    <div class="userimg lf">
        <img src=""/>
    </div>
    <div class="lf">
        <p class="nick">
            <span class="nickword"></span>
            <img src="img/man.png" alt="" class="sex1"/>
            <img src="img/woman.png" alt="" class="sex2"/>
        </p>
        <p class="loca"></p>
    </div>
</div>
<div id="addfribtn">关注</div>
<!-- 提醒-->
<p class="errer"></p>
<!--加好友完成提醒-->
<div id="sendfriendinfook" style="display:none;">
    <div>
        <span>已关注</span> <br/><span>自动跳转至首页</span>
    </div>
</div>
<!--注册加好友-->
<div class="action_menu_container" id="delmynews">
    <div class="inner">
        <div id="delmynewsform">
            <div class="action_menu">
                <a class="mweb_action_button">提示</a>
            </div>
            <div class="action_menu">
                <a class="mweb_action_button">请登录或注册完成关注操作</a>
                <!--<a class="mweb_action_button">请完善个人资料绑定好友关系</a>-->
                <!--<p>（注：若已有Pulu账号，请直接登录绑定。）</p>-->
            </div>
            <div class="action_menu">
                <div class="rt" id="delmynewsok">去注册</div>
                <div id="delmynewscancel">去登录</div>
            </div>
        </div>
    </div>
</div>
<script src="js/jquery-1.11.3.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

<script src="ftnjs/urlnote.js"></script>
<script>
    if(/#id=[0-9a-z]+/.test(location.href)){
        var fromuser=(location.href).match(/id=[0-9a-z]+/)[0].split("=")[1];
        $.cookie("fromuser",fromuser);
    }
    //扫码者 wx登录
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        //没有用户ID
        if(!$.cookie("MYID")){
            //修改地址中拼接的微信地址
            //从微信验证返回后获取openid
            if(/code=/.test(location.href)){
                var reg=new RegExp("code=[a-zA-Z0-9]*");
                var code=location.href.match(reg)[0];

                //立即获取openid 时效性
                $.ajax({
                    type:"GET",
                    url:"GetOpenId.ashx?"+code,
                    async: false,
                    success:function(data){

                        var dat=data;
                        //var openid=dat.openid;
                        //保存到本地后 进行重定向
                        $.cookie("wxopenid",dat);
                        $.cookie("myopenid",dat);
                        //拼接的fromuser先赋值为原始的转发者
                        var fromuser= $.cookie("fromuser");
                        //openid如果存在 已经关注使用了 获取自身userID
                        if(dat){
                            $.ajax({
                                type:"GET",
                                url:getwxopenidurl+$.cookie("myopenid"),
                                success:function(d){
                                    //能拿的到用户信息 //已经登录
                                    if(d.Data&&d.Data.userId.length>0){
                                        thisnick=d.Data.userNick;
                                        id=d.Data.userId;
                                        $.cookie("MYID",d.Data.userId);
                                        //修改地址 链接环信
                                        location.href="qrcodeuser.html#id="+$.cookie("fromuser");
                                    }
                                    //拿不到用户数据
                                    else{
                                        //$(".errer").html("您的用户信息不全请登录铺路后，扫码添加好友");
                                        getqrnote(fromuser,fromuser);
                                    }
                                }
                            });
                        }
                        else{
                            //$(".errer").html("您的用户信息不全请登录铺路后，扫码添加好友");
                            getqrnote(fromuser,fromuser);
                        }
                    }
                })
            }
            //页面没有微信验证信息 //页面第一次进来进行微信验证
            else{
                var loca=location.href;
                var fromuser=(location.href).match(/id=[0-9a-z]+/)[0].split("=")[1];

                $.cookie("fromuser",fromuser);
                //先微信验证获取openid 如果已经授权过了 直接页面截取openid 然后发送请求获取 用户的ID
                var reg=new RegExp("code=[a-zA-Z0-9]*");
                var returnurl2="http://www.pulu.com/weixin/qrcodeuser.html";
                location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx658c34793ecfd9f9&redirect_uri="+returnurl2+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";

            }
        }
        //有用户ID
        else{

            var loca=location.href;
            if(/id=[0-9a-z]/.test(loca)){
                var fromuser=(location.href).match(/id=[0-9a-z]+/)[0].split("=")[1];
            }
            else if($.cookie("fromuser")){
                var fromuser=$.cookie("fromuser");
            }
            else{
                var fromuser=$.cookie("MYID");
            }
            id=$.cookie("MYID");

            if($.cookie("MYID")==fromuser){
                $(".errer").html("不能关注自己");
                $("#addfribtn").attr("class","not");
            };
            getqrnote($.cookie("MYID"),fromuser);
        }
    }
    else{
        var loca=location.href;
        if(/id=[0-9a-z]+/.test(loca)){
            var fromuser=(location.href).match(/id=[0-9a-z]+/)[0].split("=")[1];
        }
        if($.cookie("MYID")){

            if($.cookie("MYID")==fromuser){
                $(".errer").html("不能关注自己");
                $("#addfribtn").attr("class","not");
            };
            getqrnote($.cookie("MYID"),fromuser);
        }
        else{
//            $(".errer").html("您的用户信息不全请登录铺路后，扫码添加好友");
            getqrnote(fromuser,fromuser);
        }
    }
    var canadd=true;

    //名片信息
    function getqrnote(myid,fromuser){

        if(myid==fromuser){
            //$("#addfribtn").attr("class","not");
        }
        if(/undefined/.test(myid)&&/undefined/.test(fromuser)){
            //全部错误
        }else if(/undefined/.test(myid)&&!/undefined/.test(fromuser)){
            myid=fromuser;
        }else if(!/undefined/.test(myid)&&/undefined/.test(fromuser)){
            fromuser=myid;
        }
        //获取他人信息
        $.ajax({
            type: "get",
            url:"https://www.pulu.com/webapi/api/puluuser/GetUserInfo?userId="+fromuser+"&friendId="+myid,
            datatype: "json",
            success: function (data) {
                console.log(data);
                $(".nickword").html(data.Data.userNick);
                if(data.Data.headimg){
                    $(".userimg img").attr("src","http://42.62.66.198:8003/"+data.Data.headimg);
                }else{
                    $(".userimg img").attr("src","img/af8.png");
                }
                if(data.Data.sex===1){$(".sex1").css("display","inline-block");}else if(data.Data.userSex===0){$(".sex2").css("display","inline-block");}
                if(data.Data.city&&data.Data.city.length>0&&data.Data.city!="null"){
                    $(".loca").html(data.Data.city);
                }
                if(data.Data.hasfocus&&$.cookie("MYID")!=fromuser){
                    $("#addfribtn").html("已关注");
                    $("#addfribtn").attr("class","not");
                }
//                if(data.Data.isfriend){
//                    $("#addfribtn").attr("class","not");
//                    $(".errer").html("已经是好友");
//                }
            }
        });
        //获取他人设置状态
        $.ajax({
            type:"GET",
            url:getCanBeVisited+"?userId="+fromuser,
            success:function(d){
                console.log(d);
                if(!d.Data){
                    //不能关注
                    $("#addfribtn").attr("class","not");
                    $(".errer").html("TA已设置不允许关注");
                }
            }
        });
    }
    //加关注
    $("#addfribtn").click(function(){
        //有用户信息
        if($.cookie("MYID")){
            if($("#addfribtn").attr("class")!="not"&&canadd){
                id=$.cookie("MYID");
                console.log(id);
                if(fromuser!= $.cookie("MYID")){
                    //直接加关注
                    canadd=false;
//                    $.ajax({
//                        type:"post",
//                        datatype:"json",
//                        url:"https://www.pulu.com/webapi/api/PuluGoodFriend/Addpulu_goodfriend",
//                        data:{"userId":fromuser,"friendId":id},
//                        success:function(d){
//                            $("#sendfriendinfook").css("display","block");
//                            setTimeout(function(){
//                                $("#sendfriendinfook").css("display","none");
//                                location.href="http://www.pulu.com/weixin/pulu.html";
//                            },1000)
//                        }
//                    });
                    var puluTopLayer={};
                    puluTopLayer.userId=fromuser;
                    puluTopLayer.ownerId=id;
                    $.ajax({
                        type:"POST",
                        url:addPuluTopLayer,
                        data:{"PuluTopLayer":puluTopLayer},
                        success:function(d){
                            $("#sendfriendinfook").css("display","block");
                            setTimeout(function(){
                                $("#sendfriendinfook").css("display","none");
                                location.href="http://www.pulu.com/weixin/pulu.html";
                            },1000)
                        }
                    })
                }
            }
        }
        //没有用户信息
        else{
            $("#delmynews").css("display","block");
//            location.href="index.html?fromuser="+id;
        }
    });
    //去登陆
    $("#delmynewscancel").click(function(){
        var fromUser="";
        if($.cookie("fromuser")){fromUser=$.cookie("fromuser")}
        else if(/#id=[0-9a-z]+/.test(location.href)){
            fromUser=(location.href).match(/id=[0-9a-z]+/)[0].split("=")[1];
        }
        location.href="http://www.pulu.com/weixin/login.html#fromuser="+fromUser;
    });
    //去完善资料
    $("#delmynewsok").click(function(){
        var fromUser="";
        if($.cookie("fromuser")){fromUser=$.cookie("fromuser")}
        else if(/#id=[0-9a-z]+/.test(location.href)){
            fromUser=(location.href).match(/id=[0-9a-z]+/)[0].split("=")[1];
        }
        location.href="http://www.pulu.com/weixin/index.html#fromuser="+fromUser;
    });
    //返回主页
    $("#logo").click(function(){
        location.href="http://www.pulu.com/weixin/pulu.html";
    })
</script>
</body>
</html>